﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

public partial class Web_Default : System.Web.UI.Page
{
    PM.PMSys.authority bauth = new PM.PMSys.authority();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["id"] != null)
            Session["typeid"] = Request.QueryString["id"].ToString();
        else
            Response.Redirect("../Index.aspx");
        if (Session["sex"] == null || Session["tid"] == null)
        {
            PM.Code.Web.alertmessage.ShowMsg("账号登录已超时，请返回重新登录。", "../Index.aspx");
            return;
        }
        string usertype = Session["UserType"].ToString().Trim();
        if (Session["typeid"].ToString() != "99")
            usertype = "1";//变为普通教师权限
        //根据申报类型或者plancode来确定是不是在申报的时间内（不用测时间了，因为新建申报页面本来就要测试时间的），
        //不在申报时间内的，直接不给链接。若在申报时间内的，给定链接并传递参数（type+ptype+plevel）或者是plancode
        //（根据plancode自己查找type+ptype+plevel信息）
        StringBuilder menuHtml = new StringBuilder();
        string sql = "select * from Sys_Menu order by menucode";
        DataTable menuTable = null;
        menuTable = PM.Code.DAL.DbHelper.ExecuteDataTableBySql(sql);
        string funfilter = bauth.GetAuthorityById(usertype);//权限控制
        funfilter = funfilter.Replace("|", " or menucode=");
        string temp = "hello" + funfilter;
        funfilter = temp.Replace("hello or ", "");
        //根据权限进行删选
        DataRow[] myrow = null;
        myrow = menuTable.Select(funfilter);
        int j= 1;//控制第一个
        foreach (DataRow row in myrow)
        {
            #region 老菜单
            ////“1”代表主菜单 
            //if (row["childmenu"].ToString()=="1")
            //{
            //    if(j==1)
            //        menuHtml.Append("<dl class=\"on\"><dt>" + row["menuname"].ToString() + "</dt>");
            //    else
            //        menuHtml.Append("<dl><dt>" + row["menuname"].ToString() + "</dt>");
            //}
            ////“0”代表子菜单
            //else if (row["childmenu"].ToString() == "0")
            //{
            //    menuHtml.Append("<dd><a href='" + row["url"].ToString() + "' target='mainwin' class='texta'><img border='0' alt='' src='"
            //        + row["ico"].ToString() + "'/>&nbsp;&nbsp;" + row["menuname"].ToString() + "</a></dd>");
            //}
            //    //“11”代表子菜单的最后一项
            //else if (row["childmenu"].ToString() == "11")
            //{
            //    menuHtml.Append("<dd><a href='" + row["url"].ToString() + "' target='mainwin' class='texta'><img border='0' alt='' src='"
            //        + row["ico"].ToString() + "'/>&nbsp;&nbsp;" + row["menuname"].ToString() + "</a></dd></dl>");
            //}
            //j++;
            #endregion
            #region 新菜单
            //长度2位是代表标题菜单
            if (row["menucode"].ToString().Trim().Length == 2)
            {
                if (j == 1)
                {
                    menuHtml.Append("<div title='" + row["menuname"].ToString() + "' style=\"overflow:auto;padding:2px 10px 10px 10px;\">");
                    j = 0;
                }
                else
                    menuHtml.Append("</div><div title='" + row["menuname"].ToString() + "' style=\"overflow:auto;padding:2px 10px 10px 10px;\">");
            }
            //长度4位是代表子菜单
            else if (row["menucode"].ToString().Trim().Length == 4)
            {
                if (row["url"].ToString() != string.Empty)
                {
                    if (row["id"].ToString().Trim() == "2" && Session["typeid"].ToString().Trim() == "99")
                        continue;
                    else
                        menuHtml.Append("<p><a href='" + row["url"].ToString() + "' target='mainwin' class='texta'><img border='0' alt='' src='"
                   + row["ico"].ToString() + "'/>&nbsp;&nbsp;" + row["menuname"].ToString() + "</a></p>");
                }
                else
                    menuHtml.Append("<p><a><img border='0' alt='' src='" + row["ico"].ToString() + "'/>&nbsp;&nbsp;" + row["menuname"].ToString() + "</a></p>");
            }
             #endregion
        }
        menuHtml.Append("</div>");
        idSlideView3.InnerHtml = menuHtml.ToString();
    }
}
